package sample.reflects;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

interface Subject {
	public String say(String name, int age);
}

class RealSubject implements Subject {

	@Override
	public String say(String name, int age) {
		return name + " " + age;
	}

}
class MyInvoke implements InvocationHandler{
	private Object obj=null;
	
	public Object bind(Object obj){
		this.obj=obj;
		return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		Object temp=method.invoke(this.obj, args);
		return temp;
	}
	
}

public class HelloSubject {
	public static void main(String[]args){
		MyInvoke demo=new MyInvoke();
		Subject sub=(Subject) demo.bind(new RealSubject());
		String info=sub.say("anqing", 1000);
		System.out.println(info);
	}

}
